#ifndef CHESSBOARD_H
#define CHESSBOARD_H

#include "Knight.h"
#include <d3d9.h>
#include <d3dx9.h>
#include "GlobalVariables.h"
#include "Vertex.h"


class ChessBoard
{

public:
	//
	static const int NONE				=	0;
	static const int CHECK				=	1;
	static const int TYPE_FREE			=	1;
	static const int TYPE_CLOSED_TOUR	=	2;


	//
	 ChessBoard(int width, int height, LPDIRECT3DDEVICE9 m_pD3Ddv);
	~ChessBoard();


	//
	void	CalcMoveMent();
	void	SetKnightTour(int startX, int startY, int endX, int endY, int type);
	void	SetSize(int width, int height);
	void	ResetAll();
	float	GetTimeElapse();
	int		GetType();
	int		GetWidth();
	int		GetHeight();


	void	InitChessBoard();
	void	SetRenderState();
	void	DrawChessBoard();


	//
	int   **m_ppBoard;
	int   **m_ppAvailMove;
	int   **m_pArrStep;

private:
	//
	void	UpdateAvailMove(int x, int y, bool increase);
	void	CalcMovement(int step, int x, int y);

	LPDIRECT3DTEXTURE9		m_pTexWhite;
	LPDIRECT3DTEXTURE9		m_pTexBlack;
	LPDIRECT3DTEXTURE9		m_pTexOrange;
	LPDIRECT3DDEVICE9		m_pD3Ddv;
	LPDIRECT3DVERTEXBUFFER9	m_pVb;
	D3DXMATRIX				m_mtxWorld;

	//
	int		m_iWidth;
	int		m_iHeight;
	bool	m_bDone;
	float	m_fTimeElapse;

	int		m_iStartX;
	int		m_iStartY;
	int		m_iEndX;
	int		m_iEndY;
	int		m_iType;
};


#endif